#!/bin/bash
#========================================================================
# Author: YSLin
# Email: 
# File Name: bc.sh
# Description: 
#   
# Edit History: 
#   2011-01-19    File created.
#========================================================================
bc <<eof
scale=4
8/3
2.6666
2.5 * 4.1/6.9
1.4855
quit
eof

#bc can be used in shell variable assignment to assign calculated values to variables:
PRICE=100
UNITS=20
AVERAGE=`echo "scale=4; $PRICE/$UNITS" | bc`
echo "AVERAGE:$AVERAGE"

#ibase表示輸入數字的base, obase表示輸出的數字的base
bc <<here
obase=16
ibase=8
400
100
77
10*3
18
quit
here

echo "Oct to Hex"
bc <<oct2hex
obase=16
ibase=10
10 + 4
oct2hex


echo "Hex to Oct"
bc <<hex2oct
obase=10
ibase=16
A + 3C
hex2oct
